cmake_minimum_required( VERSION 2.8 )

project(srp_auth)



if ( EXISTS /lib64/security )
  set(PLUGIN_DIR lib64/security)
else ( EXISTS /lib64/security )
  set(PLUGIN_DIR lib/security)
endif ( EXISTS /lib64/security )

option (BUILD_TESTS "Build test tools" ON)

find_package(Protobuf REQUIRED)

include_directories( ${PROJECT_BINARY_DIR} ${PROTOBUF_INCLUDE_DIRS} )


# Modified version of the standard CMake PROTOBUF_GENERATE_CPP. This function
# allows the .proto file to live in a directory other than the current source
# directory.
#
function(protoc_cpp SRCS HDRS PROTO_PATH)
  if(NOT ARGN)
    message(SEND_ERROR "Error protoc_cpp requires one or more .proto files as an argument")
  endif(NOT ARGN)

  set(${SRCS})
  set(${HDRS})

  foreach(FIL ${ARGN})
    get_filename_component(ABS_FIL ${FIL} ABSOLUTE)
    get_filename_component(FIL_WE ${FIL} NAME_WE)
    
    list(APPEND ${SRCS} "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.cc")
    list(APPEND ${HDRS} "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.h")

    add_custom_command(
      OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.cc"
             "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.h"
      COMMAND  ${PROTOBUF_PROTOC_EXECUTABLE}
      ARGS --cpp_out  ${CMAKE_CURRENT_BINARY_DIR} --proto_path ${PROTO_PATH} ${ABS_FIL}
      DEPENDS ${ABS_FIL}
      COMMENT "Running C++ protocol buffer compiler on ${FIL}"
      VERBATIM )
  endforeach()

  set_source_files_properties(${${SRCS}} ${${HDRS}} PROPERTIES GENERATED TRUE)
  set(${SRCS} ${${SRCS}} PARENT_SCOPE)
  set(${HDRS} ${${HDRS}} PARENT_SCOPE)
endfunction()



add_subdirectory( pam_plugin )

if (BUILD_TESTS)
  add_subdirectory( test )
endif (BUILD_TESTS)

install(PROGRAMS srp_admin DESTINATION bin)
